package com.situ.mall.user.controller;


import com.situ.mall.common.util.Result;
import com.situ.mall.pojo.entity.product.Product;
import com.situ.mall.pojo.entity.user.Collect;
import com.situ.mall.user.pojo.query.CollectQuery;
import com.situ.mall.user.service.ICollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author CKX
 * @since 2024-10-17
 */
@RestController
@RequestMapping("/user/collect")
public class CollectController {

    @Autowired
    private ICollectService collectService;

    @GetMapping("/list")
    public Result<List<Product>> list(CollectQuery collectQuery) {
        List<Product> list = collectService.selectList(collectQuery);
        return Result.ok(list);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Collect collect) {
        int code = collectService.add(collect);
        if (code == 0) {
            return Result.ok("添加成功");
        } else {
            return Result.error("不能重复收藏");
        }
    }

    @PostMapping("/delete")
    public Result delete(@RequestBody Collect collect) {
        collectService.delete(collect);
        return Result.ok("删除成功");
    }
}

